<template>
  <div>
    <el-form ref="ruleForm" :model="type" label-width="100px">
      <el-form-item label="分类名称" prop="typeName">
        <el-input v-model="type.typeName" />
      </el-form-item>
      <el-form-item label="提交" label-width="100px">
        <el-button type="primary" @click="updateType()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import typeApi from '../../../api/type'
export default {
  name: 'TypeUpdate',
  props: {
    type: {
      type: Object,
      default: null
    }
  },
  methods: {
    updateType() {
      typeApi.update(this.type).then(res => {
        if (res.code === 200) {
          this.$emit('getTypeList')
          this.$emit('closeUpdateDialog')
          this.$message.success(res.msg)
          typeApi.getList().then(res => {
            this.$store.commit('typeList/SET_TYPELIST', res.data)
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
